//
//  MTRedpacketFooterView.swift
//  MT
//
//  Created by ooops on 2020/5/15.
//  Copyright © 2020 张强. All rights reserved.
//

import Foundation
import MTCategory


protocol MTRedpacketFooterViewDelegate: NSObjectProtocol {
    
    func didClick(commitButton: UIButton)
    
}

class MTRedpacketFooterView: UIView {
    
    weak var delegate: MTRedpacketFooterViewDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        makeConstraint()
    }
    
    func cancommit(can: Bool) {
        if can {
            //commitButton.isEnabled = false
            commitButton.backgroundColor = UIColor(hex: 0xff003d)
        } else {
            //commitButton.isEnabled = true
            commitButton.backgroundColor = UIColor(hex: 0xffd2dd)
        }
    }
    
    lazy var rmbLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCSemiboldFont(40)
        l.textColor = UIColor.text.x1d1a1a
        return l
    }()
    
    lazy var commitButton: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitle("塞钱金红宝", for: .normal)
        btn.addTarget(self, action: #selector(commit(sender:)), for: .touchUpInside)
        btn.setTitleColor(.white, for: .normal)
        btn.titleLabel?.font = PingFangSCSemiboldFont(16)
        btn.backgroundColor = UIColor(hex: 0xffd2dd)
        btn.layer.cornerRadius = 25
        btn.layer.masksToBounds = true
        return btn
    }()
    
    @objc private func commit(sender: UIButton) {
        self.delegate?.didClick(commitButton: sender)
    }
    
    private func setupUI() {
        addSubview(rmbLabel)
        addSubview(commitButton)
    }
    
    private func makeConstraint() {
        rmbLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(self.snp.centerY).offset(-10)
        }
        
        commitButton.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(rmbLabel)
            make.size.equalTo(CGSize(width: 200, height: 50))
        }
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    
}
